<?php
class Cms_Model_Product extends Zend_Db_Table_Abstract
{
	protected $_name="product";
	public function init(){
		
	}
 	public function getData()
    {
    	$db=Zend_Registry::get('connectDB');
		$sql=$db->select()->from($this->_name);
		//$result=$db->fetchPairs($sql);
		$result=$db->fetchAll($sql);
		return $result;
    }
	public function getAllProducts()
    {
    	$userModel = new self();
    	$select = $userModel->select();
    	$select->order(array('productId', 'productName'));
    	return $userModel->fetchAll($select);
    }
	public function getProducts_by_id($id)
    {
    	$userModel = new self();
    	$select = $userModel->select()->where('productId='.$id);
    	$select->order(array('productId', 'productName'));
    	return $userModel->fetchAll($select);
    }
	public function getOneProduct($id)
	{
		$db=Zend_Registry::get('connectDB');
		$select=$db->select()->from($this->_name);
		$select->where("product.productId = $id");
		
		$select->joinLeft('product_category', 
					'product_category.categoryId=product.categoryId', array('categoryName'));
		$select->joinLeft('user', 
					'user.userId=product.createdBy', array('userName'));
		
		return $select->query()->fetchAll();
		
	}
    
    
}